package servlet.PropertyManagementModule.ExpenseTypeManagement;

import com.alibaba.fastjson.JSON;
import commons.r.R;
import commons.xlhUtils.MyFormatUtils;
import service.ExpenseTypeService;
import service.impl.ExpenseTypeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * servlet.PropertyManagementModule.ExpenseTypeManagement
 * User: xlh
 * Date: 2024/12/17 15:44
 * motto:推到高塔
 * Description:
 * Version: V1.0
 */
@WebServlet(name = "ExpenseTypeDeleteServlet", value = "/expenseType/deleteById")
public class ExpenseTypeDeleteServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        Integer typeId= MyFormatUtils.toInteger(request.getParameter("typeId"));

        ExpenseTypeService service = new ExpenseTypeServiceImpl();

        boolean t = service.deleteById(typeId);

        R r=!t? R.error("删除失败"):R.ok();
        //响应对象
        PrintWriter writer = response.getWriter();
        String result = JSON.toJSONString(r);
        System.out.println("UserLoginServlet:"+result);
        writer.write(result);
        writer.flush();
        writer.close();
    }
}
